import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';

export default {
  name: 'queryResult',
  components: {},
  data () {
    return {
      studentId: '',
      siteId: '',
      keyWords: '',
      status: '',
      reserveNo:'',
      paySerial:'',
      applyFee:'',
      contents: {
        applyStatus:1,
        className:'',
        applyFee:'',
        beginTime:'',
        classId:'',
        spelName:'',
        studentName:'',
        classTimeable:'',
        isPayable:'',
        endDate:''
      }
    }
  },
  mounted () {
    var _this = this
    _this.studentId = window.sessionStorage.getItem('studentId')
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.reserveNo = this.$route.query.reserveNo
    _this.goList()
  },
  methods: {
    goList () {
      var _this = this
      http.get('http://47.96.62.199/eduplatform/api/public/px/apply/getDetailByReserveNo' + '?orgId=' + _this.siteId + '&reserveNo=' + _this.reserveNo, {
      }, (res) => {
        _this.paySerial = res.data.pay.paySerial
        _this.contents.applyFee = res.data.class.feeTotal
        _this.applyFee = _this.contents.applyFee
        _this.contents.beginTime = _this.dateFormat(res.data.class.bean.beginDate)
        _this.contents.endDate = _this.dateFormat(res.data.class.bean.endDate)
        _this.contents.classId = res.data.apply.classId
        _this.contents.spelName = res.data.class.caption.spelId
        _this.contents.studentName = res.data.student.name
        _this.contents.classTimeable = res.data.class.classSchedule
        _this.contents.isPayable = res.data.pay.status
        _this.contents.className = res.data.class.bean.name
      })
    },
    comeBack () {
      window.history.go(-1)
    },
    goPayment: function (id) {
      //alert(id)
      if (this.contents.isPayable) {
        let params = '?siteId=' + this.siteId + '&id=' + id + '&studentId=' + this.studentId;
        http.get(CONSTANT.CLAZZVIEW + params, {
          siteId: this.siteId,
          id: id,
          studentId: this.studentId
        }, (res) => {
          this.content = res
        //alert(JSON.stringify(res))
          var query = {paySerial:this.paySerial,reserveNo:this.reserveNo,name:this.content.name,totalFees:this.applyFee,area:this.content.area,classNo:this.content.classNo,frontStatusName:this.content.frontStatusName,year:this.content.year,term:this.content.term,spelName:this.content.spelName,degree:this.content.degree,studentName:this.contents.studentName}
          this.$router.push({path: '/payment',query:query})
        })
      }
    },
    dateFormat(longTypeDate) {
      var dateType = "";
      var date = new Date();
      date.setTime(longTypeDate);
      dateType += date.getFullYear();  //年
      dateType += "-" + this.getMonth(date); //月
      dateType += "-" + this.getDay(date);  //日
      return dateType;
    },
    getMonth(date) {
      var month = "";
      month = date.getMonth() + 1; //getMonth()得到的月份是0-11
      if(month<10){
        month = "0" + month;
      }
      return month;
    },
    getDay(date) {
      var day = "";
      day = date.getDate();
      if(day<10){
        day = "0" + day;
      }
      return day;
    }
  }
}
